﻿using GDGeek;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace MrPP.UX
{
    public class UIEffectRunner : MonoBehaviour
    {
        List<UIEffect> list_ = new List<UIEffect>();
        [SerializeField]
        private float _interval = 0.3f;
        public Task hide()
        {
            TaskSet ts = new TaskSet();
            foreach (UIEffect e in list_)
            {
                
                ts.push(e.hide());

            }
            return ts;
        }
  
        public void init()
        {
            list_.Clear();
            UIEffect[] effects = this.GetComponentsInChildren<UIEffect>();
            list_ = new List<UIEffect>(effects);
            foreach (var ef in list_) {
                ef.init();
            }
        }

        public Task show()
        {
            TaskSet ts = new TaskSet();
            foreach (UIEffect e in list_) {
                TaskList tl = new TaskList();
                tl.push(new TaskWait((e.layer-1) * _interval));
                tl.push(e.show());
                ts.push(tl);
            }
            return ts;
        }
    }
}
